package cn.hchaojie.camp.day11;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import org.junit.Test;

public class DemoChar {
	@Test
	public void test() throws UnsupportedEncodingException {
//		char c = 'A';
//		char z = '中';
//		
//		System.out.println(z);
//		
//		String s = "中";
//		System.out.println(Arrays.toString(s.getBytes()));
//		System.out.println(Arrays.toString(s.getBytes("utf-8")));
//		System.out.println(Arrays.toString(s.getBytes("gbk")));
		
//		System.out.println((int) 'A');
//		System.out.println((char) 256);
//		System.out.println((char) 120);
		
		System.out.println(Arrays.toString("A".getBytes("gbk")));
	}
	
	@Test
	public void test2() {
		try (FileOutputStream out = new FileOutputStream("a.txt");) {
//			out.write('A');
			// 字节流，一次写一个字节，写中文的时候可能会丢失信息
			out.write('中');
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void test3() {
		try (FileInputStream in = new FileInputStream("a.txt");) {
			byte[] bytes = new byte[10];
			int count = in.read(bytes);
			System.out.println(count);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
